def mergeort(nums: list[int]) -> list[int]:
    if len(nums) <= 1: return nums
    mid = len(nums) // 2
    left = nums[:mid]
    right = nums[mid:]
    left = mergeort(left)
    right = mergeort(right)
    i = j = 0
    a = []
    while i < len(left) and j < len(right):
        if left[i] < right[j]:
            a.append(left[i])
            i += 1
        else:
            a.append(right[j])
            j += 1
    if i < len(left):
        a.extend(left[i:])
    if j < len(right):
        a.extend(right[j:])
    return a


if __name__ == '__main__':
    nums = [12, 11, 13, 5, 6, 7]
    a = mergeort(nums)
    print(a)
